<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="${initParam.url }/statics/css/detail.css" rel="stylesheet">
<link href="${initParam.url }/statics/css/compilewrite.css"
	rel="stylesheet">
<script src="${initParam.url}/statics/js/jquery-1.12.4.js"></script>
<script type="text/javascript">
/*加载省下拉选*/  
$(function () {  
    $.ajax({  
        type: "post",  
        url: "/property/address/getProvince",  
        dataType: "json",
        success: function (data) {  
        	 for (var i = 0; i < data.length; i++) {  
                $('#province_code').append("<option value='" + data[i].id + "' >" + data[i].province + "</option>");  
            }  
        },  
        
        error: function () {  
            alert("加载省失败");  
        }  
    });  
});  
/*加载市下拉选*/  
function getCity() {  
    var id = $("#province_code").val();  
    $("#city_code").empty();  
    $("#area_code").empty();  
    $.ajax({  
        type: "post",  
        url: "/property/address/getCity",  
        data: {"id": id},  
        dataType: "json",
        success: function (data) {  
        	$('#city_code').append("<option value='' selected='selected' >" + '———市———' + "</option>");  
            $('#area_code').append("<option value='' selected='selected' >" + '———区———' + "</option>");  
            for (var i = 0; i < data.length; i++) {  
                $('#city_code').append("<option value='" + data[i].id + "' >" + data[i].city + "</option>");  
            }  
        },  
        error: function () {  
            alert("加载市失败");  
        }  
    });  
}  
;  
/*加载地区下拉选*/  
function getArea() {  
    var id = $("#city_code").val();  
    $("#area_code").empty();  
    $.ajax({  
        type: "post",  
        url: "/property/address/getArea",  
        data: {"id": id},  
        dataType: "json",
        success: function (data) {  
            $('#area_code').append("<option value='' selected='selected' >" + '———区———' + "</option>");  
            for (var i = 0; i < data.length; i++) {  
                $('#area_code').append("<option value='" + data[i].id + "' >" + data[i].district + "</option>");  
            }  
        },  
        error: function () {  
            alert("加载区失败");  
        }  
    });  
}   
</script>
<script>
	$(document).ready(function() {
		$("#phone").blur(checkPhone);
		$("#name").blur(checkUsername);

		$("#btn").click(function() {
			var flag = true;
			
			if (!checkUsername()) {
				flag = false;
			}
			if (!checkPhone()) {
				flag = false;
			}
			if(!checkAddress()){
				flag = false;
			}
			if (flag == true) {

				$("#jo").submit();
			}
		})
	})
	
	function checkAddress(){
		var $fname = $("#area_code");
		var $divID = $("#DivAddress");
		$divID.html("");
		if ($fname.val() == "") {
			$divID.html("请选择小区地址");
			return false;
		}
		return true;
	}
	
	//验证密码
	function checkPhone() {
		var $phone = $("#phone");
		var $divID = $("#DivPhone");
		$divID.html("");
		if ($phone.val() == "") {
			$divID.html("手机号码不能为空");
			return false;
		}
		if ($phone.val().length != 11) {
			$divID.html("请输入正确的手机号码");
			return false;
		}	
		return true;
	}
	//验证名字
	function checkUsername() {
		var $fname = $("#name");
		var $divID = $("#DivUsername");
		$divID.html("");
		if ($fname.val() == "") {
			$divID.html("小区名称不能为空");
			return false;
		}
		return true;
	}
</script>
</head>

<body>
	<div
		style="width: 1090px; height: 490px; background-color: #FFF; margin: 20px;">
		<h4
			style="background-color: #9FB2C2; padding-left: 10px; color: #516D8A; line-height: 40px;">
			<img alt="" src="${initParam.url}/statics/images/title.jpg">
			添加平台管理员信息
		</h4>

		<div class="sp">
			<form action="addcommunity" method="post" id="jo">

				<br /> <span style="color: red;">${error }</span>
				<table>
					<tr>
						<td class="tr-1">小区地址:</td>
						<td width="600px">
							<select class="select" id="province_code" name="province_code" onchange="getCity()"> 
								<option value="">———省———</option>   
            				</select> 
            				<select class="select" id="city_code" name="city_code" onchange="getArea()">  
            					<option value="">———市———</option>  
            				</select> 
            				<select class="select" id="area_code" name="area_code">  
            					<option value="">———区———</option>  
            				</select> &nbsp;<span id='DivAddress'></span>
						</td>
					<tr>
					<tr>
						<td class="tr-1">小区名称:</td>
						<td><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;" name="name"
							id="name" type="text" />&nbsp;<span id='DivUsername'></span></td>
					</tr>
					<tr>
						<td class="tr-1">安保号码:</td>
						<td><input class="tr-2 form-control"
							style="width: 220px; height: 25px; display: inline;"
							name="phone" id="phone" type="text" />&nbsp;<span
							id='DivPhone'></span></td>
					</tr>
					<tr>
						<td colspan="2" class="td-1"><input type="button"
							class="btn btn-default" value="确定" id="btn"> <input
							type="button" class="btn btn-default"
							onclick="history.go(-1)"
							value="取消"></td>
					</tr>
				</table>

			</form>

		</div>
	</div>
</body>
</html>